<template>
	<view  :style="colorStyle">
	     <view class="hh">
	     	<button open-type="launchApp" app-parameter="wechat"  @launchapp="launchapp" v-if="flag">返回APP</button>
	     </view>
	</view>
</template>

<script>
	import Routine from '@/libs/routine.js';
	import colors from '@/mixins/color.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		allinpayApi
	} from '@/api/order.js';
	import {
		mapGetters
	} from 'vuex';
	import {
		getUserInfo
	} from '@/api/user.js';
	export default {
		computed: mapGetters(['isLogin']),
		mixins: [colors],
		data() {
			return {
				//返回按钮的开关
				flag:false,
				storeId: 0,
				pay_close: false,
				isShowAuth: false,
				// 订单号 
				uni: "",
				// 支付类型
				paytype: "",
				//环境
				from: "",
				//h5和app有
				quitUrl: "",
				// 组合支付的金额
				use_money: "",
			}
		},
		onLoad(options) {
			this.uni = options.uni;
		},
		onShow() {
			// #ifdef MP
			// 小程序静默授权
			Routine.getCode()
				.then(code => {
                    this.openPay(code)
				})
				.catch(res => {
					uni.hideLoading();
				});
			// #endif
		},
		methods: {
			//返回app
			launchapp(){
		        
			},
		     //调起微信支付
			openPay(code){
				allinpayApi({
					code,
					uni: this.uni
				}).then(res => {
					if (res.data.result === undefined) return this.$util.Tips({
						title: '缺少支付参数'
					});
					let jsConfig = res.data.result.jsConfig;
					let mp_pay_name = "";
					if (uni.requestOrderPayment) {
						mp_pay_name = 'requestOrderPayment'
					} else {
						mp_pay_name = 'requestPayment'
					}
					uni[mp_pay_name]({
						timeStamp: jsConfig.timeStamp,
						nonceStr: jsConfig.nonceStr,
						package: jsConfig.package,
						signType: jsConfig.signType,
						paySign: jsConfig.paySign,
						success: function(res) {
							 this.flag=true;
							uni.hideLoading();
							return this.$util.Tips({
								title: res.msg,
								icon: 'success'
							});
						},
						fail: function(e) {
							this.flag=true;
							uni.hideLoading();
							return this.$util.Tips({
								title: '取消支付'
							});
						},
						complete: function(e) {
							uni.hideLoading();
							this.flag=true;
							if (e.errMsg == 'requestPayment:cancel') return this.$util
								.Tips({
									title: '取消支付'
							});
						},
					});
				}).catch(err => {
					this.flag=true;
					return this.$util.Tips({
						title: err
					})
				});
				
			},

			/**
			 * 支付成功回调
			 * 
			 */
			pay_complete: function() {
				this.pay_close = false;
				uni.navigateTo({
					url: '/pages/goods/order_pay_status/index?order_id=' + this.orderInfo.order_id + '&msg=' +
						'支付成功' +
						'&type=3' + '&totalPrice=' + this.orderInfo.pay_price
				})
			},
			/**
			 * 支付失败回调
			 * 
			 */
			pay_fail: function() {
				this.pay_close = false;
				uni.navigateTo({
					url: '/pages/goods/order_pay_status/index?order_id=' + this.orderInfo.order_id + '&msg=' +
						'取消支付' +
						'&type=3' + '&totalPrice=' + this.orderInfo.pay_price
				})
			},
			
		}
	}
</script>

<style lang="scss">
.hh{
	background-color: #fff;
	height: 100vh;
}
</style>